<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title>汽运主单列表</title>
        <% include("/common/common_css_js.html"){} %>
    </head>
    <body>
        <div style="padding-bottom: 5px;">
            <div id="queryForm" class="uc-toolbaroverflow" _borderStyle="border-top:0;">
                <span>主单号：</span><input id="keyMasterBillCode" name="keyMasterBillCode" emptyText="请输入主单号"  class="mini-textbox" selectOnFocus="true" required="false" requiredErrorText="主单号不能为空" />
                <span class="separator"></span>
                <span>承运方式:</span><input id="keyTransportWayId" name="keyTransportWayId" class="mini-combobox" style="width:150px;" textField="name" valueField="id" emptyText="请选择..."
                                         required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择承运方式"/>
                <span class="separator"></span>
                <span>开单日期：</span>
                <input id="keyOpenMasterBillStartDate" name="keyOpenBillStartDate"  class="mini-datepicker"   format="yyyy-MM-dd"/>--<input id="keyOpenMasterBillEndDate" name="keyOpenBillEndDate" class="mini-datepicker"  format="yyyy-MM-dd"/>

                <span class="separator"></span>
                <span>总运费结费状态:</span>
                <input id="keyFreightAmountStatusId" name="keyFreightAmountStatusId" class="mini-combobox" style="width:120px;" textField="name" valueField="id" emptyText="请选择..."
                       required="false" allowInput="false" showNullItem="true" nullItemText="请选择..." requiredErrorText="没有选择总运费结费状态"/>

                <div style="margin-top: 5px"></div>
                <% if(so.hasPermission("autoMasterBillPay:query")){%>
                    <a class="mini-button" iconCls="icon-search" onclick="searchBill()">查询</a>
                <% } %>

                <% if(so.hasPermission("autoMasterBillPay:queryCndClear")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearSearch()">清空查询条件</a>
                <% } %>

                <span class="separator"></span>

                <% if(so.hasPermission("autoMasterBillPay:clearAutoTotalCharge")){%>
                    <a class="mini-button" iconCls="icon-new" onclick="clearCharge(400)">结清总运费</a>
                <% } %>

                <span class="separator"></span>

                <% if(so.hasPermission("autoMasterBillPay:download")){%>
                    <#download_grid id="downloadGrid" theGridId="datagrid1" theFileName="汽运主单信息表"/>
                <% } %>

                <div style="margin-top: 5px"></div>
                <span style="color: red;font-weight: bold">
                    <span>注:1.【初始配载分单号】表示主单初始配载时所包含的分单号 </span>
                    <span style="margin-left: 10px">2.主单如果做过全拉货操作，则主单下配载分单会被清空，而列表中显示的【初始配载分单号】不会清除(用于标识地面运费成本标识) </span>
                </span>

            </div>
        </div>

        <div class = "mini-fit">
            <div id="datagrid1" class="mini-datagrid"
                 style="width: 100%; height: 100%;"
                 url="${base}/pages/finance_manage/pay/queryAutoMasterBillList" idField="id"
                 showPager="true" pageSize="20" sizeList="[10,20,30,50,100]"
                 multiSelect = "true" allowResize="true"
                 showGroupsSummary="true" showSummaryRow="true" summaryPosition="bottom"
                 allowSortColumn = "true"
                 sortField="createTime"
                 sortOrder="desc"
                 ondrawsummarycell="summaryRight"
            >
                <div property="columns">
                    <div type="checkcolumn" ></div>
                    <div field="id" width="140" headerAlign="center" align="center" allowSort="true" renderer="showMasterBillRender">汽运主单号</div>
                    <div field="loadNativeBillIds" width="140" headerAlign="center" align="center">初始配载分单号</div>
                    <div field="totalFreightAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">总运费</div>
                    <div field="freightAmountStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">运费结清状态</div>
                    <div field="transportWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">承运方式</div>
                    <div field="transportUnitId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"selfOrOutUnit"}' renderer="commonRender">承运单位</div>
                    <div field="transportUnitMasterBillCodeIds" width="140" headerAlign="center" align="center" allowSort="true">承运单位主单号IDS</div>
                    <div field="startCityId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">始发站</div>
                    <div field="destCityId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"city"}' renderer="commonRender">目站市</div>

                    <div field="autoLineRoadName" width="140" headerAlign="center" align="center" allowSort="true">线路名称</div>
                    <div field="sendWayId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">派送方式</div>
                    <div field="pickUpPointName" width="140" headerAlign="center" align="center" allowSort="true">提货点名称</div>
                    <div field="pickUpPointPhone" width="140" headerAlign="center" align="center" allowSort="true">提货点电话</div>
                    <div field="pickUpPointAddress" width="140" headerAlign="center" align="center" allowSort="true">提货点地址</div>

                    <div field="licensePlateNumber" width="140" headerAlign="center" align="center" allowSort="true">车牌号</div>
                    <div field="deliveryTime" width="140" headerAlign="center" align="center" allowSort="true" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">走货时间</div>
                    <div field="driver" width="140" headerAlign="center" align="center" allowSort="true">驾驶员</div>
                    <div field="driverPhone" width="140" headerAlign="center" align="center" allowSort="true">驾驶员电话</div>
                    <div field="goodsTypeId" width="140" headerAlign="center" align="center" allowSort="true" data-options='{cacheName:"sysDic"}' renderer="commonRender">货物类型</div>

                    <div field="totalNumber" width="140" headerAlign="center" align="right" allowSort="false" summaryType="sum">总件数</div>
                    <div field="actualWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">实际重量</div>
                    <div field="chargeableWeight" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">计费重量</div>
                    <div field="weightRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">重量费率</div>
                    <div field="volume" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">体积</div>
                    <div field="volumeRate" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer">体积费率</div>

                    <div field="freightAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">运费合计</div>
                    <div field="otherCharges" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">其他费用</div>
                    <div field="otherChargesComment" width="140" headerAlign="center" align="center" allowSort="true">其他费用说明</div>

                    <div field="masterBillPaymentMethodId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">付款方式</div>
                    <div field="dropAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">调整金额</div>
                    <div field="settlementAmount" width="140" headerAlign="center" align="right" allowSort="false" renderer="public_moneyRenderer" summaryType="sum">结算金额</div>

                    <div field="openMasterBillDate" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">开单日期</div>
                    <div field="openMasterBillDepartmentId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"department"}' renderer="commonRender">开单部门</div>
                    <div field="openMasterBillUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">开单人</div>
                    <div field="comment" width="140" headerAlign="center" align="center" allowSort="false">备注</div>
                    <div field="dropStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">拉货状态</div>
                    <div field="settlementStatusId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysDic"}' renderer="commonRender">结算状态</div>

                    <div field="createTime" width="140" headerAlign="center" align="center" allowSort="false" dateFormat="yyyy-MM-dd HH:mm:ss" renderer="ondayRenderer">创建时间</div>
                    <div field="createUserId" width="140" headerAlign="center" align="center" allowSort="false" data-options='{cacheName:"sysUser"}' renderer="commonRender">创建用户</div>
                </div>
            </div>

        </div>

        <script type="text/javascript">
            mini.parse();

            let keyMasterBillCode = mini.get("keyMasterBillCode");
            let keyTransportWayId = mini.get("keyTransportWayId");
            let keyOpenMasterBillStartDate = mini.get("keyOpenMasterBillStartDate");
            let keyOpenMasterBillEndDate = mini.get("keyOpenMasterBillEndDate");
            let keyFreightAmountStatusId = mini.get("keyFreightAmountStatusId");

            let grid = mini.get("datagrid1");

            // 定义结清状态
            let settlementStatus = {uncleared:321, cleared:322};

            // 定义费用类型
            let chargeType = {nativeBillAgentDeliveryCharge:381, nativeBillServiceCharge:382, ariMasterBillGroundCharge:390, airMasterBillTotalAmount:391, autoMasterBillTotalAmount:400};

            // 代表的是分单
            let billType = {nativeBill:371, airMasterBill:372, autoMasterBill:373};

            $(function () {
                // 承运方式下拉列表
                let keyTransportWayIdJsonData=commonRenderSysDicDropListByKey("sysDic","XT_DIC_TRANSPORT_WAY");
                keyTransportWayId.load(keyTransportWayIdJsonData);

                // 总运费结费状态
                let keyFreightAmountStatusIdJsonData = commonRenderSysDicDropListByKey("sysDic","XT_DIC_SETTLEMENT_STATUS");
                keyFreightAmountStatusId.load(keyFreightAmountStatusIdJsonData);

                // 加载列表数据
                grid.load();
            });

            /**
             * 清空查询条件
             */
            function clearSearch(){
                let form = new mini.Form("#queryForm");
                form.clear();
            }

            /**
             * 根据查询条件查询分单
             */
            function searchBill(){
                let form = new mini.Form("#queryForm");
                let data = form.getData(true);
                grid.load(data);
            }


            // 展示主单号时显示其超链接
            function showMasterBillRender(e){
                // renderer="showMasterBillRender"
                let masterBillId = e.value;
                let htmlStr = "<a href='javascript:void(0);' onclick='showViewMasterBill(\""+ masterBillId +"\")'>" + masterBillId + "</a>";

                return htmlStr;
            }

            function showViewMasterBill(masterBillId){
                let tabUrl="${base}/pages/master_bill_manage/auto/showUpdateMasterBill?opType=view&id=" + masterBillId;
                let tabTitle = "汽运主单查看";
                parent.window.addTabToMainPage(tabTitle,tabTitle,tabUrl);
            }


            /**
             * 结清费用
             */
            function clearCharge(typeId){
                let selectItems = grid.getSelecteds();
                if(selectItems.length == 0){
                    showAlert("没有选择需要结清费用的汽运主单行!",null);
                    return;
                }
                // 开始遍历
                let clearedBillIds = "";
                let idArray=[];
                for(let billObj of selectItems){
                    let statusId;
                    if(typeId == chargeType.autoMasterBillTotalAmount){
                        statusId = billObj.freightAmountStatusId;
                    }

                    if(statusId == settlementStatus.cleared){
                        clearedBillIds += billObj.id + " ";
                    }
                    else{
                        let obj;
                        if(typeId == chargeType.autoMasterBillTotalAmount){
                            obj={billId:billObj.id,billAmount:billObj.totalFreightAmount};
                        }
                        idArray.push(obj);
                    }
                }

                if(clearedBillIds.length > 0){
                    if(typeId == chargeType.autoMasterBillTotalAmount){
                        showAlert("主单号【" + clearedBillIds + "】，总运费结清状态为【已结清】，请不要选择!");
                    }
                    return;
                }

                // 到此校验全部成功，可以入库了
                let clearNatvieBillServiceChargeUrl = "${base}/pages/finance_manage/pay/clearedBillCharge";
                let billTypeIdValue = billType.autoMasterBill;
                let ret = public_getServerData(clearNatvieBillServiceChargeUrl, {idList:idArray,billTypeId:billTypeIdValue,clearChargeTypeId:typeId,statusId:settlementStatus.cleared});
                showAlert(ret.message,function (){
                    grid.reload();
                });

            }

            /**
             * 设置底部统计样式
             * @param e
             */
            function summaryRight(e){
                e.cellStyle="text-align:right;color:red;font-size:18px;font-weight:bold";
            }
        </script>


    </body>
</html>